package jinyilw.swing.rlaf.ui;

import javax.swing.JComponent;
import javax.swing.JSeparator;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import java.awt.Dimension;
import java.awt.Graphics;
/**
 * @author Jinyi
 */
public class RToolBarSeparatorUI extends RSeparatorUI
{
	public static ComponentUI createUI(JComponent c)
	{
		return new RToolBarSeparatorUI();
	}

	@Override
	protected void installDefaults(JSeparator s)
	{
		Dimension size = ((JToolBar.Separator) s).getSeparatorSize();

		if (size == null || size instanceof UIResource)
		{
			JToolBar.Separator sep = (JToolBar.Separator) s;
			size = (Dimension) (UIManager.get("ToolBar.separatorSize"));
			if (size != null)
			{
				if (sep.getOrientation() == JSeparator.HORIZONTAL)
				{
					size = new Dimension(size.height, size.width);
				}
				sep.setSeparatorSize(size);
			}
		}
	}

	@Override
	public void paint(Graphics g, JComponent c)
	{
	}

	@Override
	public Dimension getPreferredSize(JComponent c)
	{
		Dimension size = ((JToolBar.Separator) c).getSeparatorSize();
		if (size != null)
			return size.getSize();
		return null;
	}
}
